package com.five.bi.utils;

import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;

import java.io.FileWriter;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;


public class SnakeYamlTest {

    private volatile static AtomicInteger num = new AtomicInteger(1);

    private static Integer add(){
        return num.getAndIncrement();
    }
    /**
     * 生成yaml文件
     * @param configTx 参数
     */
    public static String createCoonYaml(Map<String, Object> configTx) throws IOException {
        DumperOptions options = new DumperOptions();
        options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
        options.setDefaultScalarStyle(DumperOptions.ScalarStyle.PLAIN);//标量格式
        Yaml yaml = new Yaml(options);
        String str = yaml.dump(configTx);
        FileWriter fw = null;
        try {
            Integer n = add();
            fw = new FileWriter("C:/Users/后来/Desktop/bi/src/main/resources/"+n+".yaml");
            fw.write(str);
            fw.flush();
            System.out.println("生成yaml完成");
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            fw.close();
        }
        return str;
    }
}
